<template>
  <div class="tpl43-sale">
    <!-- 标题 -->
    <section class="recommend-top">
      <p>FLASH SALE</p>
      <div class="title">
        <b class="left"></b>
        <i>限时促销</i>
        <b class="right"></b>
      </div>
    </section>
    <!-- 折叠轮播 -->
    <div ref="getHeight" class="imgAdv-box" v-if="tplItemData.showType == 1">
      <!-- TODO 小程序端用swiper -->
      <wx-swiper class="my-swipe" :style="`height: ${imgadvWxH}`" :circular="true" indicator-color="#ebedf0" indicator-active-color="#FE5000" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
      <!-- <van-swipe v-else class="my-swipe" :autoplay="3000" indicator-color="#FE5000">
        <van-swipe-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" />
          </a>
        </van-swipe-item>
      </van-swipe> -->
    </div>
    <!-- 分开展示 -->
    <section class="members-imgad" v-else>
      <ul class="clearfix">
        <li v-for="(item,index) in tplItemData.dataset" :key="index" :style="{'margin-bottom':tplItemData.margin+'px'}">
          <a @click="openLink(item.link)" :title="item.showtitle">
            <img :src="item.pic" width="100%" />
          </a>
        </li>
      </ul>
    </section>
    <section class="activity-goods" v-if="tplItemData.datasetlist">
      <ul>
        <li v-for="(item,index) in tplItemData.datasetlist" :key="index" :class="['list'+(index+1)]" :style="{'background-image': 'url('+item.pic+')'}">
          <a @click="openLink(item.link)">
            <span v-if="item.showTitle">{{item.title}}</span>
          </a>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
import Vue from 'vue'
import { openPage } from '@/utils/utils'
// import { Swipe, SwipeItem } from 'vant'
// Vue.use(Swipe)
// Vue.use(SwipeItem)
export default Vue.extend({
  props: {
    tplItemData: {
      type: Object // 传入参数的类型
    }
  },
  data() {
    return {
      imgadvWxH: '0',
      showIndicators: true,
      autoplay: true,
    }
  },
  methods: {
    // TODO 小程序跳转
    openLink(link) {
      openPage(link)
    },
    // TODO 小程序swiper获取图片高度
    onImageLoad(event){
      const imgHeight = event.detail.height
      if(imgHeight > parseFloat(this.imgadvWxH)){
        this.imgadvWxH = imgHeight+'px'
      }
    }
  }
})
</script>

<style lang="scss">
.tpl43-sale{
  .recommend-top {
    color: #c5c5c5;
    font-size: 26px;
    text-align: center;
    padding: 30px 0;
    .title {
      font-size: 36px;
      color: #666;
      margin-top: 20px;
      position: relative;
      b.left,  b.right {
        width: 20%;
        border: 1px solid #dadada;
        display: inline-block;
        transform: translate(0,-10px);
      }
      i {
        padding: 0 10px;
      }
    }
  }
  .imgAdv-box{
    img{
      width: 100%;
    }
  }
  .members-imgad{
    li{
      margin-bottom: 10px;
      &:last-child{
        margin-bottom: 0;
        img{
          width: 100%;
        }
      }
    }
  }
  .activity-goods{
    background: #fff;
    ul {
      padding: 20px 10px 0;
      column-count: 2;
      column-gap: 0;
      li {
        margin: 0 10px 20px;
        width: calc(100% - 20px);
        height: 0;
        break-inside: avoid;
        overflow: hidden;
        position: relative;
        background-size: cover;
        background-repeat: no-repeat;
        a{
          display: block;
        }
        span {
          width: 90%;
          padding: 10px 0;
          background: rgba(0,0,0,.5);
          display: inline-block;
          position: absolute;
          bottom: 0;
          left: 50%;
          transform: translate(-50%,-10px);
          color: #fff;
          text-align: center;
        }
        &.list1,
        &.list4 {
          padding-bottom: calc(100% - 20px);
        }
        &.list2, 
        &.list3 {
          padding-bottom: calc((100% - 20px) *(892 / 700));
        }
      }
    }
  }
}
</style>